package com.gzedu.common.sys.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;

import com.gzedu.common.sys.dao.IBaseDao;
import com.gzedu.common.sys.model.BaseEntity;
import com.gzedu.common.sys.service.IBaseService;
import com.gzedu.common.util.page.Page;
import com.gzedu.module.modle.user.User;

public class BaseService<T extends BaseEntity> implements IBaseService<T> {
	@Autowired
	private IBaseDao<T> baseDao;

	public int insert(T e) {
		// TODO Auto-generated method stub
		e.setCreate_date(new Date());
		e.setCreator(getUserInfo().getId());
		return this.baseDao.insert(e);
	}

	public void batchInsert(List<T> data) {
		// TODO Auto-generated method stub
		for(T t : data){
			this.insert(t);
		}
	}

	public long replace(T e) {
		// TODO Auto-generated method stub
		return this.baseDao.replace(e);
	}

	public void batchReplace(List<T> data) {
		// TODO Auto-generated method stub
		for(T t : data){
			this.replace(t);
		}
	}

	public int updateById(T e) {
		// TODO Auto-generated method stub
		e.setModifty_date(new Date());
		e.setModifier(getUserInfo().getId());
		return this.baseDao.updateById(e);
	}

	public T getOne(T entity) {
		// TODO Auto-generated method stub
		return this.baseDao.getOne(entity);
	}

	public List<T> select(T entity) {
		// TODO Auto-generated method stub
		return this.baseDao.select(entity);
	}

	public Page<T> page(T entity, int page, int pagesize) {
		// TODO Auto-generated method stub
		return this.baseDao.page(entity, page, pagesize);
	}

	public T getById(String id) {
		// TODO Auto-generated method stub
		return this.baseDao.getById(id);
	}

	public List<T> getAll() {
		// TODO Auto-generated method stub
		return this.baseDao.getAll();
	}

	public int count(T entity) {
		// TODO Auto-generated method stub
		return 0;
	}

	public int delete(T entity) {
		// TODO Auto-generated method stub
		return this.baseDao.delete(entity);
	}

	public int deleteByPrimary(String primary) {
		// TODO Auto-generated method stub
		return this.baseDao.deleteByPrimary(primary);
	}

	public int clear() {
		// TODO Auto-generated method stub
		return 0;
	}

	public List<T> findAllList() {
		// TODO Auto-generated method stub
		return baseDao.findAllList();
	}
	
	
	private User getUserInfo(){
		Subject currentUser = SecurityUtils.getSubject(); 
		User user = (User)currentUser.getSession().getAttribute("loginUser");
		return user;
	}

	
	

}
